package com.shoesdemo.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Vibrator;
import android.util.Log;

import com.shoesdemo.R;

/**
 * created by yukun
 * date  2020/12/28
 * desc  震动
 */
public class VibratorUtils {

    private static SoundPool mSoundPool;

    public static void start(Context context) {
        Vibrator vibrator = (Vibrator) context.getSystemService(context.VIBRATOR_SERVICE);
        vibrator.vibrate(1000);
    }

    public static void startMusic(Context context) {
        int type = SpUtil.getMusic();
        startMusic(type, context);
    }

    public static void startMusic(int type, Context context) {
        if (type == 0) {
            Vibrator vibrator = (Vibrator) context.getSystemService(context.VIBRATOR_SERVICE);
            vibrator.vibrate(500);
        } else if (type == 1) {
            mSoundPool.play(1, 1, 1, 0, 0, 1);
        } else {
            //nothing
        }
    }

    public static void initSoungPoll(Context context) throws Exception {
        //设置最多可容纳5个音频流，音频的品质为5
        mSoundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 5);
        mSoundPool.load(context, R.raw.bibi, 1);
    }

}
